KOptional

value class KOptional<T>(source)

Optional implementation that allows holding null values.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
inline fun get(): T

Retrieves the value if it's present, or throws NoSuchElementException otherwise.

Link copied to clipboard
inline fun getOrNull(): T?

Retrieves the value if it's present, or returns null.

Inherited functions

Link copied to clipboard
inline fun <T, R> KOptional<T>.fold(ifPresent: (T) -> R, ifEmpty: () -> R): R

Transforms the value with the ifPresent function if it's present, or the one provided by ifEmpty otherwise.

Link copied to clipboard
inline fun <T> KOptional<T>.getOrDefault(default: T): T

Returns the value if it's present, or default otherwise.

Link copied to clipboard
inline fun <T> KOptional<T>.getOrElse(action: () -> T): T

Returns the value if it's present, or the one provided by the action otherwise.

Link copied to clipboard
inline fun <T> KOptional<T>.ifEmpty(action: () -> Unit): KOptional<T>

Executes the provided action if the value is absent.

Link copied to clipboard
inline fun <T> KOptional<T>.ifPresent(action: (T) -> Unit): KOptional<T>

Executes the provided action if the value is present.

Link copied to clipboard
inline fun <T, R> KOptional<T>.map(action: (T) -> R): KOptional<R>

Transforms the value with the provided action if it's present.